package com.tanhua.dubbo.api;

/**
 * @Author: cl
 * @Date: 2022/5/2 - 05 - 02
 * @Description:
 */

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mappers.QuestionMapper;
import com.tanhua.model.domain.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 设置问题服务
 */
@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 根据用户id查询设置问题
     *
     * @param userId
     * @return
     */
    @Override
    public Question findByUserId(Long userId) {
        Question question = questionMapper.selectOne(
                Wrappers.<Question>lambdaQuery()
                        .eq(Question::getUserId, userId)
        );
        return question;
    }

    /**
     * 添加问题
     *
     * @param question
     */
    @Override
    public void save(Question question) {
        questionMapper.insert(question);

    }

    /**
     * 修改问题
     *
     * @param question
     */
    @Override
    public void update(Question question) {
        questionMapper.updateById(question);
    }
}
